﻿-- =============================================
-- Script Template
-- =============================================



--Contacto
--TipoDocumento
--Categoria
-- ListaDistribucion
-- Campania


if not exists (select 1 from sys.columns where name = 'EmpresaId' and object_id = object_id('Contacto'))
begin
alter table Contacto add EmpresaId int not null default(1)
end

GO

if not exists (select 1 from sys.objects where name = 'FK_Contacto_Empresa' and parent_object_id = object_id('Contacto'))
begin
alter table Contacto add constraint FK_Contacto_Empresa foreign key (EmpresaId) references Empresa(Id)
end 

GO


if not exists (select 1 from sys.columns where name = 'EmpresaId' and object_id = object_id('TipoDocumento'))
begin
alter table TipoDocumento add EmpresaId int not null default(1)
end

GO

if not exists (select 1 from sys.objects where name = 'FK_TipoDocumento_Empresa' and parent_object_id = object_id('TipoDocumento'))
begin
alter table TipoDocumento add constraint FK_TipoDocumento_Empresa foreign key (EmpresaId) references Empresa(Id)
end 

GO


if not exists (select 1 from sys.columns where name = 'EmpresaId' and object_id = object_id('Categoria'))
begin
alter table Categoria add EmpresaId int not null default(1)
end

GO

if not exists (select 1 from sys.objects where name = 'FK_Categoria_Empresa' and parent_object_id = object_id('Categoria'))
begin
alter table Categoria add constraint FK_Categoria_Empresa foreign key (EmpresaId) references Empresa(Id)
end 

GO


if not exists (select 1 from sys.columns where name = 'EmpresaId' and object_id = object_id('ListaDistribucion'))
begin
alter table ListaDistribucion add EmpresaId int not null default(1)
end

GO

if not exists (select 1 from sys.objects where name = 'FK_ListaDistribucion_Empresa' and parent_object_id = object_id('ListaDistribucion'))
begin
alter table ListaDistribucion add constraint FK_ListaDistribucion_Empresa foreign key (EmpresaId) references Empresa(Id)
end 

GO


if not exists (select 1 from sys.columns where name = 'EmpresaId' and object_id = object_id('Campania'))
begin
alter table Campania add EmpresaId int not null default(1)
end

GO

if not exists (select 1 from sys.objects where name = 'FK_Campania_Empresa' and parent_object_id = object_id('Campania'))
begin
alter table Campania add constraint FK_Campania_Empresa foreign key (EmpresaId) references Empresa(Id)
end 

GO







